<?php
// $Id$

/**
 * Controller_Admin_Config 控制器
 */
class Controller_Admin_Config extends Controller_Abstract
{

	function actionIndex()
	{
		$form = new Form_Config(url('config'));
		$config = Configs::find()->getOne();
		if (!$config->id())
		{
			$insert = array(
				'sitename'=>'测试站点',
				'siteurl'=>'http://',
				'isopen'=>'0',
			);
			$config = new Configs($insert);
			$config->save();
		}
		if ($this->_context->isPOST())
		{
			//$return_array = array('statusCode' => Helper_Dwz::DWZ_STATUS_ERROR,'message'=>'');
			// 参数校验
			if ($form->validate($_POST))
			{
				$value = $form->values();
				$config->changeProps($value);
				$config->save();
				$return_array = array('statusCode' => Helper_Dwz::DWZ_STATUS_OK,'message'=>'操作已成功!');
			}else{
				// 参数校验返回
				foreach ($form->elements() as $element){
					if (!$element->isValid()){
						$err = implode(',', $element->errorMsg());
						$return_array['message'] .= $err.'<br>';
					}
				}
			}
			return $this->success('成功');
			//return json_encode($return_array);
		}
		$form->import($config->toArray());
		$this->_view['form'] = $form;
	}
}